<?php

#--------------------------------------------------
# ALL INCLUDES + STANDARD-VALUES
#--------------------------------------------------
include_once ("include/config.inc");
include_once ("include/template.inc");
include_once ("include/class.db.php5");
include_once ("include/class.tools.php5");
$svo = new db("svoptik");
$tools = new tool();

include_once ("include/global_fix_extern.inc");

include_once ("stats_inc.php5");

if (empty ($complete))
	$complete = 0;
if (empty ($team_id))
	$team_id = 1;
$team_data = $svo->readRecordset("select t.*, s.*, g.*, l.* from " . $table['Team'] . " as t, " . $table['G_Team'] . " as g, " . $table['Saison'] . " as s, " . $table['Liga'] . " as l where t.stats_team_id=" . $team_id . " && t.stats_team_global_id=g.stats_team_global_id && l.stats_leagues_id=t.stats_team_league && s.stats_season_id=" . $current_season_id . ";");

#--------------------------------------------------
# CREATE TEMPLATE
#--------------------------------------------------
$t = new Template("templates", "keep");
$t->set_file(array (
	"page" => "svoptik.tpl",
	"ticker" => "ticker.tpl",
	"navi" => "navi.tpl",
	"team" => "player_stats.tpl"
));
#--------------------------------------------------
$t->set_var(array (
	"FORWARD" => ""
));

#--------------------------------------------------
# CREATE NAVIGATION RIGHT
#--------------------------------------------------
if ($team == "U20 m I")
	$team = "U 20 I";
$links = "";
$m = 1;

$url[0] = array (
	"URL" => "",
		"URL-TEXT" => $team, //$team_data['stats_team_global_class'] . " " . $team_data['stats_team_global_index'],
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "team.php5?team_id=" . $team_id . "&cat=News",
	"URL-TEXT" => "-&nbsp;News",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "team.php5?team_id=" . $team_id . "&cat=Team",
	"URL-TEXT" => "-&nbsp;Team",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
/*   $url[$m++] = array("URL"   => "",
	                "URL-TEXT" => "".$tools->html_replace($player_data['stats_player_global_name']),
	                "ONCLICK"  => "",
                   "TARGET"   => "_self");
*/
$url[$m++] = array (
	"URL" => "team_tab.php5?team_id=" . $team_id,
	"URL-TEXT" => "-&nbsp;Tabelle",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "team_schedule.php5?team_id=" . $team_id . "&complete=0",
	"URL-TEXT" => "-&nbsp;Spielplan",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "team_stats.php5?team_id=" . $team_id,
	"URL-TEXT" => "-&nbsp;Teamstatistiken",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
$url[$m++] = array (
	"URL" => "",
	"URL-TEXT" => "SPACER",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
/*
  if (check_player_id()) {
      $season_query = $svo->doSQL("select distinct s.* from ".$table['Player']." as p, ".$table['Team']." as t, ".$table['Saison']." as s where p.stats_player_id_global=".$player_id." && t.stats_team_id=p.stats_player_team_id && t.stats_team_season=s.stats_season_id ORDER BY s.stats_season_name desc;");
      if ($svo->countRows($season_query) > 1) {
        $url[] = array("URL"      => "",
                       "URL-TEXT" => "Archiv",
                       "ONCLICK"  => "",
                       "TARGET"   => "_self");
         while ($row = $svo->getRecordset($season_query)) {
              if ($row['stats_season_id'] != $current_season_id) {
                $url[] = array("URL"      => "javascript:alert('Archiv im Aufbau');", # player_stats.php5?player_id=".$player_id
                               "URL-TEXT" => "Saison ".$row['stats_season_name'],
                               "ONCLICK"  => "",
                               "TARGET"   => "_self");
                }
          }
      }
    }
 */
for ($i = 0; $i < count($url); $i++) {
	if ($url[$i]['URL-TEXT'] != "SPACER") {
		if (!empty ($url[$i]['URL'])) {
			$slink = "<a href=\"" . $url[$i]['URL'] . "\" class=\"sitenav\" target=\"" . $url[$i]['TARGET'] . "\" onClick=\"" . $url[$i]['ONCLICK'] . "\">" . $tools->html_replace($url[$i]['URL-TEXT']) . "</a>";
		} else
			$slink = "<b>" . $tools->html_replace($url[$i]['URL-TEXT']) . "</b>";
	} else
		$slink = "&nbsp;";
	$links .= "
	        <tr height=\"15\">
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
				<td valign=\"top\" class=\"sitenav\">" . $slink . "</td>
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			</tr>
	       ";
}

$t->set_var(array (
	"LINKS" => $links,
	"BANNER" => $banner
));
$right_nav = $t->parse("", "navi", true);
#--------------------------------------------------

#--------------------------------------------------
# CREATE ALL-TIME SAME THINGS
#--------------------------------------------------
include_once ("include/sameThings.php5");

#--------------------------------------------------

#--------------------------------------------------
# CREATE CONTENT "STATS"
#--------------------------------------------------
function check_player_id() {
	global $svo, $table, $player_id;
	if ($svo->doSQL("select * from " . $table['G_Player'] . " where stats_player_global_id=" . $player_id . ";"))
		return true;
	else
		return false;
}

if (!isset ($game_id))
	$game_id = 0;
if (!check_player_id()) {
	$player = "Keine Daten zum ausgew&auml;hlten Spieler vorhanden.";
	$game = "";
} else {
	$player_data = get_player_data($player_id);

	// Counter
	$svo->doSQL("update " . $table['G_Player'] . " set stats_player_global_clicks=" . ($player_data['stats_player_global_clicks'] + 1) . " where stats_player_global_id=" . $player_id . ";");

	if (is_file("images/players/" . $player_data['stats_player_global_photo']))
		$link_foto = "<img src=\"images/players/" . $player_data['stats_player_global_photo'] . "\" width=\"150\" height=\"200\" border=\"0\" alt=\"\" title=\"" . $tools->html_replace($player_data['stats_player_global_vname']) . " " . $tools->html_replace($player_data['stats_player_global_name']) . "\">";
	else
		$link_foto = "<img src=\"standard/spacer.gif\" width=\"150\" height=\"200\" border=\"0\" alt=\"\" title=\"noch kein Foto von " . $tools->html_replace($player_data['stats_player_global_vname']) . " " . $tools->html_replace($player_data['stats_player_global_name']) . "\">";
	$player = "
	  <table width=\"480\" style=\"border: solid 1px #820400\" cellpadding=\"2\" cellspacing=\"0\">
	    <tr>
	        <td width=\"50%\" align=\"left\" valign=\"top\" class=\"text\">
	            <table width=\"200\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">
	                <tr>
	                    <td width=\"33%\" class=\"text\" align=\"left\" valign=\"top\">&nbsp;</td>
	                    <td width=\"64%\" class=\"text\" align=\"left\" valign=\"top\">&nbsp;</td>
	                </tr>
	                <tr>
	                    <td width=\"33%\" class=\"text\" align=\"left\" valign=\"top\"><b>Name:</b></td>
	                    <td width=\"64%\" class=\"text\" align=\"left\" valign=\"top\">" . $tools->html_replace($player_data['stats_player_global_name']) . "</td>
	                </tr>
	                <tr>
	                    <td width=\"33%\" class=\"text\" align=\"left\" valign=\"top\"><b>Vorname:</b></td>
	                    <td width=\"64%\" class=\"text\" align=\"left\" valign=\"top\">" . $tools->html_replace($player_data['stats_player_global_vname']) . "</td>
	                </tr>
	                <tr>
	                    <td width=\"33%\" class=\"text\" align=\"left\" valign=\"top\"><b>Gr&ouml;&szlig;e:</b></td>
	                    <td width=\"64%\" class=\"text\" align=\"left\" valign=\"top\">" . $tools->html_replace($player_data['stats_player_global_height']) . " m</td>
	                </tr>
	                <tr>
	                    <td width=\"33%\" class=\"text\" align=\"left\" valign=\"top\"><b>Gewicht:</b></td>
	                    <td width=\"64%\" class=\"text\" align=\"left\" valign=\"top\">" . $tools->html_replace($player_data['stats_player_global_weight']) . " kg</td>
	                </tr>
	                <tr>
	                    <td width=\"33%\" class=\"text\" align=\"left\" valign=\"top\"><b>Position:</b></td>
	                    <td width=\"64%\" class=\"text\" align=\"left\" valign=\"top\">" . $tools->html_replace($player_data['stats_player_global_position']) . "</td>
	                </tr>
	                <tr>
	                    <td width=\"33%\" class=\"text\" align=\"left\" valign=\"top\"><b>Sonstiges:</b></td>
	                    <td width=\"64%\" class=\"text\" align=\"left\" valign=\"top\">" . $tools->html_replace($player_data['stats_player_global_notes']) . "</td>
	                </tr>
	            </table>
	        <td width=\"50%\" align=\"right\" valign=\"top\">" . $link_foto . "</td>
	    </tr>
	  </table>
	  ";
	$get_player_ids = $svo->doSQL("select p.* from " . $table['Player'] . " as p, " . $table['Team'] . " as t where p.stats_player_id_global=" . $player_id . " && t.stats_team_id=p.stats_player_team_id && t.stats_team_season=" . $current_season_id . ";");
	if ($svo->countRows($get_player_ids) > 0) {
		$game = "";
		while ($row = $svo->getRecordset($get_player_ids)) {
			if ($svo->countRows($svo->doSQL("select stats_game_stats_id from " . $table['Stats'] . " where stats_game_stats_player_id=" . $row['stats_player_id'] . ";")) > 0) {
				$teams_data = $svo->readRecordset("select t.*, gl.*, g.* from " . $table['Team'] . " as t, " . $table['Liga'] . " as l,  " . $table['G_Liga'] . " as gl, " . $table['G_Team'] . " as g where t.stats_team_id=" . $row['stats_player_team_id'] . " && t.stats_team_league=l.stats_leagues_id && gl.stats_leagues_global_id=l.stats_leagues_global_id && g.stats_team_global_id=t.stats_team_global_id;");
				$game .= "
				            <table width=\"480\" cellpadding=\"2\" cellspacing=\"0\" border=\"0\">
				                <tr>
				                    <td align=\"left\" valign=\"top\" class=\"text\"><br><b>" . $tools->html_replace($teams_data['stats_leagues_global_name'] . " (" . $teams_data['stats_leagues_global_class'] . ") - " . $teams_data['stats_team_global_name'] . " " . $teams_data['stats_team_global_index']) . "</b></td>
				                </tr>
				            </table>
				            ";
				$game .= get_team_gamestats($row['stats_player_team_id'], $row['stats_player_id']);
			}
		}
	} else
		$game = "Keine Statistiken zum ausgew&auml;hlten Spieler in der aktuellen Saison verf&uuml;gbar.";
}
$t->set_var(array (
	"GAMES" => $game,
	"PLAYERDATA" => $player
));
$content = $t->parse("", "team", true);
#--------------------------------------------------

#--------------------------------------------------
# PARSE & OUTPUT
#--------------------------------------------------
$t->set_var(array (
	"sitenav" => "TEAMS -> <a href=\"team.php5?team_id=" . $team_id . "\" class=\"sitenav\" target=\"_self\">" . $tools->html_replace(strtoupper($team_data['stats_team_global_name'] . " - " . $team_data['stats_team_global_class'] . " " . $team_data['stats_team_global_index']
)) . "</a> -> SPIELERPROFIL &quot;" . $tools->html_replace(strtoupper($player_data['stats_player_global_name'] . ", " . $player_data['stats_player_global_vname'])) . "&quot;", "ticker" => $ticker, "content" => $content . "<br>", "navi" => $right_nav,
	"SYNCHRONIZE" => " "));

$t->parse("ALL", "page", true);
$t->p("ALL");
?>
